package com.sunjob.mroresumeproject.dao;

import com.sunjob.common.domain.mroresume.CKParts;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository//声明持久层
public interface CKPartsMapper {
    //查询部件定检履历的所有记录
    @Select("select count(*) from ck_partsresume where statues=1 ")
    int querycount();

    //第一页查询五条部件定检履历记录
    @Select("select * from ck_partsresume where statues=1 limit #{pages},#{size} ")
    List<CKParts> queryCKparts(int pages, int size);

    //搜索框条件查询可以是部件定检编号或者部件名称
    @Select("select * from ck_partsresume where checkid=#{checkid} and statues=1")
    @Results({
            @Result(property = "checkid",column = "checkid"),
            @Result(property = "partstypes",column = "partstypes"),
            @Result(property = "management",column = "management"),
            @Result(property = "partsinitial",column = "partsinitial"),
            @Result(property = "partsend",column = "partsend"),
            @Result(property = "failreason",column = "failreason"),
            @Result(property = "money",column = "money"),
            @Result(property = "starttime",column = "starttime"),
            @Result(property = "endtime",column = "endtime"),
            @Result(property = "statues",column = "statues"),
            })
    List<CKParts> queryCKparts2(String checkid);


    //部件定检履历记录新增
    @Insert("insert into ck_partsresume values(#{checkid},#{CKcontent},#{partstypes},#{management},#{partsinitial},#{partsend},#{failreason},#{money},#{starttime},#{endtime},#{statues})")
    void insertCKparts(CKParts ckParts);

    //部件定检履历记录新增后查询
    @Select("select * from ck_partsresume where statues=1")
    @Results({
            @Result(property = "checkid",column = "checkid"),
            @Result(property = "CKcontent",column = "CKcontent"),
            @Result(property = "partstypes",column = "partstypes"),
            @Result(property = "management",column = "management"),
            @Result(property = "partsinitial",column = "partsinitial"),
            @Result(property = "partsend",column = "partsend"),
            @Result(property = "failreason",column = "failreason"),
            @Result(property = "money",column = "money"),
            @Result(property = "starttime",column = "starttime"),
            @Result(property = "endtime",column = "endtime"),
            @Result(property = "statues",column = "statues"),
    })
    List<CKParts> queryCKparts5();

    //部件定检履历根据当前checkid编辑的一条记录查询
    @Select("select * from ck_partsresume where checkid=#{checkid} and statues=1")
    @Results({
            @Result(property = "checkid",column = "checkid"),
            @Result(property = "partstypes",column = "partstypes"),
            @Result(property = "management",column = "management"),
            @Result(property = "partsinitial",column = "partsinitial"),
            @Result(property = "partsend",column = "partsend"),
            @Result(property = "failreason",column = "failreason"),
            @Result(property = "money",column = "money"),
            @Result(property = "starttime",column = "starttime"),
            @Result(property = "endtime",column = "endtime"),
            @Result(property = "statues",column = "statues"),
    })
    List<CKParts> queryCKpartsone(Long checkid);

    //部件定检履历记录编辑修改数据
    @Update("update ck_partsresume set CKcontent=#{CKcontent},partstypes=#{partstypes},management=#{management},partsinitial=#{partsinitial},partsend=#{partsend},failreason=#{failreason},money=#{money},starttime=#{starttime},endtime=#{endtime} where checkid=#{checkid}")
    void updateCKparts(String checkid, String CKcontent, String partstypes, String management, String partsinitial, String partsend, String failreason, String money, String starttime, String endtime);

    //部件定检履历记录的删除,修改statues
    @Update("update ck_partsresume set statues=0 where checkid=#{checkid}")
    void deleteCKparts(String checkid);

    @Update("update ck_partsresume set statues=0 where checkid=#{checkid}")
    void deleteCKpartsone(String s);
}
